//package com.captjack.netty.client;
//
//import com.captjack.common.util.thread.ThreadPoolFactory;
//
//import java.util.ArrayList;
//import java.util.Arrays;
//import java.util.Date;
//import java.util.List;
//import java.util.concurrent.CompletableFuture;
//import java.util.concurrent.ExecutorService;
//import java.util.concurrent.Executors;
//
///**
// * Description description.....
// *
// * @author Jack Sparrow
// * @version 1.0.0
// * @date 2018/7/26 14:56
// * package com.captjack.netty.client
// */
//public class AsyncTest {
//
//    public static void main(String[] args) {
//        long start = System.currentTimeMillis();
//        // 结果集
//        List<String> list = new ArrayList<>();
//        ExecutorService executorService = ThreadPoolFactory.newFixedThreadPool(10, "completable-");
//        List<Integer> taskList = Arrays.asList(2, 1, 3, 4, 5, 6, 7, 8, 9, 10);
//
//        CompletableFuture[] completableFutures = taskList.stream()
//                .map(number -> CompletableFuture.supplyAsync(() -> calc(number), executorService).thenApply(result -> Integer.toString(result)).whenComplete(((s, throwable) -> {
//                    System.out.println("任务" + s + "完成!result=" + s + "，异常 e=" + throwable + "," + new Date());
//                    list.add(s);
//                }))).toArray(CompletableFuture[]::new);
//        CompletableFuture.allOf(completableFutures).join();
//        System.out.println("list=" + list + ",耗时=" + (System.currentTimeMillis() - start));
//    }
//
//    public static Integer calc(Integer i) {
//        try {
//            System.out.println(Thread.currentThread().getName());
//            if (i == 1) {
//                //任务1耗时3秒
//                Thread.sleep(3000);
//            } else if (i == 5) {
//                //任务5耗时5秒
//                Thread.sleep(5000);
//            } else {
//                //其它任务耗时1秒
//                Thread.sleep(1000);
//            }
//            System.out.println("task线程：" + Thread.currentThread().getName() + "任务i=" + i + ",完成！+" + new Date());
//        } catch (InterruptedException e) {
//            e.printStackTrace();
//        }
//        return i;
//    }
//
//}
